import React, {Component} from 'react';
import {connect} from 'react-redux'
import {add,jian} from '../store/actions/main'
import http from "../api/base";

class Page001 extends Component{
    constructor(props) {
        super(props);
        this.state = {
            apiData: {}
        }
    }

    render() {
        return(
            <div>
                <button onClick={() =>this.props.add()}>测试+</button>
                <button onClick={() =>this.props.jian()}>测试-</button>
                <div>{this.props.count}</div>
                <button onClick={this.testApi}>网络测试</button>
                <div>{JSON.stringify(this.state.apiData)}</div>
            </div>
        )
    }

    testApi = () =>{
        let data = {
            member_id:'UlVWb1RGZDZkVGhtUTJVclJUa3ljSEZ1V0dac2FIaEhhbFJEVkhSS2NEZExhMWwzZEVoT01sUkRkejA9',
            from_channel:'app',
            system_id:'10005',
            page:1,
            search:{
                "pay_channel":"",
                // "from_channel":this.result.toString(),
                "money_start":'',
                "money_end":"",
                "time_start":'',
                "time_end":'',
                store_id:''
            }

        }
        http.get('/api/userinfo/buy',data).then(res =>{
            console.log(res);
            this.setState({apiData:res})

        })
    }
}


//以下所有功能都是react-redux提供的
const mapStateToProps = (state) => {
    return {
        count: state.appStatus.count,
    };
};

const mapDispatchToProps = (dispatch) => {
    return {
        add: () => dispatch(add()),
        jian: () => dispatch(jian()),
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(Page001);